import { ref } from 'vue';
import { useAuthStore } from '@/store/modules/auth';
import { get } from '@/service/api/api';

let topFormModel;
let bottomFormModel;
const moduleNoSearchData = ref(null);

const moduleNoList = ref([]);

function getModuleNoList() {
  get('/rcerp/agv/erp/findProdNo').then(({ data, error }) => {
    if (!error) {
      moduleNoList.value = data.map(item => {
        return {
          label: item.moduleNo,
          value: item.moduleNo
        };
      });
    }
  });
}

const authStore = useAuthStore();
export default {
  url: '/qms/agv/PackCheck800/find',
  addUrl: '/qms/agv/PackCheck800/add',
  editUrl: '/qms/agv/PackCheck800/update',
  delUrl: '/qms/agv/PackCheck800/deleteBatch',
  searchFormList: [
    {
      type: 'input',
      key: 'moduleNo',
      label: '生产型号',
      placeholder: '请输入生产型号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    },
    {
      type: 'input',
      key: 'serialNum',
      label: '单据号',
      placeholder: '请输入单据号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    },
    {
      type: 'select',
      key: 'state',
      label: '审核状态',
      placeholder: '请选择审核状态',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 5,
      selectOptions: [
        {
          value: '0',
          label: '待领班审核'
        },
        {
          value: '1',
          label: '待修改'
        },
        {
          value: '2',
          label: '待主管审核'
        },
        {
          value: '3',
          label: '审核完成'
        }
      ]
    },
    {
      type: 'dateRangePicker',
      key: 'time',
      label: '日期',
      span: 24,
      md: 12,
      lg: 10,
      xl: 8,
      xxl: 6
    }
  ],
  searchParam: ref({
    moduleNo: null,
    state: null,
    time: null
  }),
  column: [
    {
      key: 'dataIndex',
      dataIndex: 'dataIndex',
      title: '序号',
      width: 70,
      fixed: 'left',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'moduleNo',
      dataIndex: 'moduleNo',
      title: '生产型号',
      width: 150,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'serialNum',
      dataIndex: 'serialNum',
      title: '单据号',
      width: 130,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'date',
      dataIndex: 'date',
      title: '日期',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'cycle',
      dataIndex: 'cycle',
      title: '周期',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'state',
      dataIndex: 'state',
      title: '状态',
      width: 120,
      align: 'center',
      checked: true,
      ellipsis: true,
      customRender: ({ record }) => {
        return ['待领班审核', '待修改', '待主管审核', '审核完成'][record.state];
      }
    },

    {
      key: 'custProdNoAdd',
      dataIndex: 'custProdNoAdd',
      title: '代码',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'innerNum',
      dataIndex: 'innerNum',
      title: '内包实物数量',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'packNum',
      dataIndex: 'packNum',
      title: '包数',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'outerNum',
      dataIndex: 'outerNum',
      title: '外箱标签数量',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'innerSerial',
      dataIndex: 'innerSerial',
      title: '内标流水号',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'outerSerial',
      dataIndex: 'outerSerial',
      title: '外标流水号',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'innerCycle',
      dataIndex: 'innerCycle',
      title: '内标周期',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'packMaterial',
      dataIndex: 'packMaterial',
      title: '真空包装材质',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'bad1',
      dataIndex: 'bad1',
      title: '包装袋有无破损漏气',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'bad2',
      dataIndex: 'bad2',
      title: '有无温湿度卡',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'bad3',
      dataIndex: 'bad3',
      title: '有无防潮珠',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'bad4',
      dataIndex: 'bad4',
      title: '包装纸是否破损',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'bad5',
      dataIndex: 'bad5',
      title: '纸箱规格是否符合要求(堆垛,防雨标识)',
      width: 280,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'decide',
      dataIndex: 'decide',
      title: '判定',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'operator',
      dataIndex: 'operator',
      title: '操作员',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'foreman',
      dataIndex: 'foreman',
      title: '领班审核',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'foremanTime',
      dataIndex: 'foremanTime',
      title: '领班审核时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'examiner',
      dataIndex: 'examiner',
      title: '主管审核',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'examinerTime',
      dataIndex: 'examinerTime',
      title: '主管审核时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'remark',
      dataIndex: 'remark',
      title: '备注',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'createTime',
      dataIndex: 'createTime',
      title: '创建时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'updateTime',
      dataIndex: 'updateTime',
      title: '修改时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'updateBy',
      dataIndex: 'updateBy',
      title: '修改人',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    }
  ],
  scroll: { x: 2500, y: 'auto' },
  topFormList: [
    // 用于获取model
    {
      type: 'getModel',
      hidden: true,
      handle(topModel, personModle) {
        topFormModel = topModel;
        bottomFormModel = personModle;
      }
    },
    {
      type: 'select',
      key: 'moduleNo',
      label: '生产型号',
      span: 12,
      rule: {
        required: true,
        message: '请输入生产型号',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      search: true,
      selectOptions: moduleNoList,
      showSelectOtherBtn: true,
      selectOtherBtnText: '查询',
      handleSelectOtherBtnClick: () => {
        get('/rcerp/agv/erp/findCustNo', {
          moduleNo: topFormModel.value.moduleNo
        }).then(({ data, error }) => {
          if (!error) {
            Object.keys(topFormModel.value).forEach(item => {
              topFormModel.value[item] = data[item] || topFormModel.value[item];
            });
          }
        });
      }
    },

    {
      type: 'input',
      key: 'custProdNoAdd',
      label: '代码',
      span: 12,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'datePicker',
      key: 'date',
      label: '日期时间',
      span: 8,
      rule: {
        required: true,
        message: '请选择日期时间',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      showTime: true
    },

    {
      type: 'input',
      key: 'cycle',
      label: '周期',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'input',
      key: 'innerNum',
      label: '内包实物数量',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'input',
      key: 'packNum',
      label: '包数',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'input',
      key: 'outerNum',
      label: '外箱标签数量',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'input',
      key: 'innerSerial',
      label: '内标流水号',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'input',
      key: 'outerSerial',
      label: '外标流水号',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'input',
      key: 'innerCycle',
      label: '内标周期',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'select',
      key: 'packMaterial',
      label: '真空包装材质',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          label: '白色气泡膜+PE',
          value: '白色气泡膜+PE'
        },
        {
          label: '红色气泡膜+PE',
          value: '红色气泡膜+PE'
        }
      ]
    },

    {
      type: 'radio',
      key: 'bad1',
      label: '包装袋有无破损漏气',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          value: '有',
          label: '有'
        },
        {
          value: '无',
          label: '无'
        }
      ]
    },

    {
      type: 'radio',
      key: 'bad2',
      label: '有无温湿度卡',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          value: '有',
          label: '有'
        },
        {
          value: '无',
          label: '无'
        }
      ]
    },

    {
      type: 'radio',
      key: 'bad3',
      label: '有无防潮珠',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          value: '有',
          label: '有'
        },
        {
          value: '无',
          label: '无'
        }
      ]
    },

    {
      type: 'radio',
      key: 'bad4',
      label: '包装纸是否破损',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          value: '是',
          label: '是'
        },
        {
          value: '否',
          label: '否'
        }
      ]
    },
    {
      type: 'radio',
      key: 'bad5',
      label: '纸箱规格是否符合要求(堆垛,防雨标识)',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          value: '是',
          label: '是'
        },
        {
          value: '否',
          label: '否'
        }
      ]
    },

    {
      type: 'select',
      key: 'decide',
      label: '判定',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          value: '是',
          label: '是'
        },
        {
          value: '否',
          label: '否'
        }
      ]
    },
    {
      type: 'textarea',
      key: 'remark',
      label: '备注',
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      textareaRows: 1,
      span: 24
    }
  ],
  bottomList: [
    {
      type: 'input',
      key: 'operator',
      label: '操作者',
      defaultValue: authStore.userInfo.user.nickName || authStore.userInfo.user.userName,
      disabled: true,
      span: 8
    },
    {
      type: 'input',
      key: 'foreman',
      label: '领班审核',
      disabled: true,
      span: 8
    },
    {
      type: 'input',
      key: 'examiner',
      label: '主管审核',
      disabled: true,
      span: 8
    }
  ],
  modalHeight: '70vh',
  modleSearchUrlObj: {
    lotId: '/rcerp/agv/erp/findByLotNo'
  },
  modalClose() {
    moduleNoSearchData.value = null;
  },
  pageMounted() {
    getModuleNoList();
  }
};
